package org.glut.controller;

import org.glut.bean.HWJC;
import org.glut.service.HWJCService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
/**
 * 红外检测
 * @author 啊林
 * @date 2022/1/10
 * @time 0:05
 */
public class HWJCController {
    @Autowired
    private HWJCService hwjcService;


    @RequestMapping("/hwpower")
    public String hwjcpower(){
        return "/myviews/hwpower";
    }

    /**
     * 获取红外检测bean
     * @return
     */
    @RequestMapping("/getHWJC")
    @ResponseBody
    public HWJC getHWJC(String id) {
        if ("1".equals(id)) {
            return HWJCService.hwjc1;
        }else{
            return HWJCService.hwjc2;
        }
    }
    
    /**
     * 获取厨房燃气上传时间List
     * @return
     */
    @RequestMapping("/gethwjcTimeDate")
    @ResponseBody
    public List<String> gethwjcTimeDate(String id){
        List<String> timeList;
        if ("1".equals(id)) {
            timeList = hwjcService.hwjctimeList1;
        }else {
            timeList = hwjcService.hwjctimeList2;
        }
        if (timeList.size() > 30) {
//            List<String> list = timeList.subList(timeList.size() - 30, timeList.size() - 1);
//            hwjcService.timeList.remove(0);
//            hwjcService.timeList = new ArrayList<>(list);
            timeList.remove(0);
        }
        return timeList;
    }
    

    /**
     * 获取厨房燃气上传电量List
     * @return
     */
    @RequestMapping("/gethwjcpowerDate")
    @ResponseBody
    public List<String> gethwjcpowerDate(String id){
        List<String> yhList;
        if ("1".equals(id)) {
            yhList = hwjcService.hwjcpower1;
        }else {
            yhList = hwjcService.hwjcpower2;
        }
        if (yhList.size() > 30) {
//                List<String> list = yhList.subList(yhList.size() - 30, yhList.size() - 1);
//                hwjcService.yhList = new ArrayList<>(list);
            int size = yhList.size();
            yhList = yhList.subList(size-30,size);
        }
        return yhList;
    }

}
